package com.example.demo;

import com.example.demo.yanglq.component.bloomfilter.RedisBloomFilter2;
import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.google.common.hash.Hashing;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;

@SpringBootTest
class RedisBloomFilterTestApplicationTests2 {
    private static final int TOTAL = 10000;
    private static final double FPP = 0.0005;
    @Test
    void contextLoads() {
    }

    @Test
    void test() {
        RedisBloomFilter2 redisBloomFilter = RedisBloomFilter2.create((long) TOTAL, FPP);
        redisBloomFilter.resetBitmap();
        BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), TOTAL, FPP);

        IntStream.range(0, /* 3* */50).boxed()
                .map(i -> Hashing.md5().hashInt(i).toString())
                .collect(toList()).forEach(s -> {
            redisBloomFilter.put(s);
            bloomFilter.put(s);
        });

        String str1 = Hashing.md5().hashInt(1).toString();
        String str2 = Hashing.md5().hashInt(9999).toString();
        String str3 = "abcdefghijklmnopqrstuvwxyz123456";
        String str4 = Hashing.md5().hashInt(23).toString();
        System.out.println(redisBloomFilter.mightContain(str1) + ":" + bloomFilter.mightContain(str1));
        System.out.println(redisBloomFilter.mightContain(str2) + ":" + bloomFilter.mightContain(str2));
        System.out.println(redisBloomFilter.mightContain(str3) + ":" + bloomFilter.mightContain(str3));
        System.out.println(redisBloomFilter.mightContain(str4) + ":" + bloomFilter.mightContain(str4));
    }



}
